<html>
<head><meta charset="utf-8"><title>mutuallly recursive async fn #62284 · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html">mutuallly recursive async fn #62284</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="169725745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169725745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169725745">(Jul 05 2019 at 17:58)</a>:</h4>
<p>So <span class="user-mention" data-user-id="127859">@Taylor Cramer</span> I'm looking at <a href="https://github.com/rust-lang/rust/issues/62284" target="_blank" title="https://github.com/rust-lang/rust/issues/62284">https://github.com/rust-lang/rust/issues/62284</a> a bit more closely</p>



<a name="169726150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169726150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169726150">(Jul 05 2019 at 18:04)</a>:</h4>
<p>I'm a bit surprised by the example itself -- it is returning a boxed future from an async fn?</p>



<a name="169726163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169726163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169726163">(Jul 05 2019 at 18:04)</a>:</h4>
<p>It seems like this cycles is tied to the way we implement <code>impl Trait</code></p>



<a name="169726166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169726166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169726166">(Jul 05 2019 at 18:04)</a>:</h4>
<p>i.e., auto trait leakage</p>



<a name="169726289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169726289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169726289">(Jul 05 2019 at 18:07)</a>:</h4>
<p>this actually raises the issue of whether <code>async fn</code> should desugar to <code>impl Future</code> or <code>impl Future + Send</code> again, as the most obvious workaround is to desugar to something returning + Send</p>



<a name="169727587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169727587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169727587">(Jul 05 2019 at 18:28)</a>:</h4>
<p>( cc <span class="user-mention" data-user-id="203289">@boats</span> )</p>



<a name="169732370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169732370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169732370">(Jul 05 2019 at 19:57)</a>:</h4>
<p>I left <a href="https://github.com/rust-lang/rust/issues/62284#issuecomment-508830428" target="_blank" title="https://github.com/rust-lang/rust/issues/62284#issuecomment-508830428">several comments on the issue itself</a>. In general, recursive async functions are a bit of a pain right now, is roughly my conclusion, and the solutions are a bit tricky.</p>



<a name="169903629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169903629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169903629">(Jul 08 2019 at 20:48)</a>:</h4>
<p>This isn't an interesting issue with respect to cycles at all</p>



<a name="169903668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169903668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169903668">(Jul 08 2019 at 20:49)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> the issue is that it thinks there is a cycle, but it shouldn't, because the object returned by the <code>async fn</code> never gets stored into a local that is live across an <code>await</code> point</p>



<a name="169903682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169903682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169903682">(Jul 08 2019 at 20:49)</a>:</h4>
<p>It's just bad at determining which temporaries need to be analyzed</p>



<a name="169903842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169903842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169903842">(Jul 08 2019 at 20:51)</a>:</h4>
<p>Yeah, but it seems more interesting when there <em>are</em> actual cycles</p>



<a name="169903892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169903892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169903892">(Jul 08 2019 at 20:52)</a>:</h4>
<p>that's pretty painful right now</p>



<a name="169903904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169903904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169903904">(Jul 08 2019 at 20:52)</a>:</h4>
<p>it's just not something I had on my radar</p>



<a name="169903970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169903970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169903970">(Jul 08 2019 at 20:53)</a>:</h4>
<p>Sure, but the issue here is that there's a specific case that is pretty common, doesn't have cycles, and should be easily resolved</p>



<a name="169904087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169904087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169904087">(Jul 08 2019 at 20:54)</a>:</h4>
<p>Why is this scenario common?</p>



<a name="169904216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169904216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169904216">(Jul 08 2019 at 20:56)</a>:</h4>
<p>it happens whenever you want to make a recursive <code>async fn</code></p>



<a name="169904248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169904248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169904248">(Jul 08 2019 at 20:56)</a>:</h4>
<p>I've had a number of people at work try and do this and wound up repeating the steps that I showed in the issue</p>



<a name="169904256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169904256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169904256">(Jul 08 2019 at 20:56)</a>:</h4>
<p>(pull the call out into a separate function that does the boxing)</p>



<a name="169904262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169904262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169904262">(Jul 08 2019 at 20:56)</a>:</h4>
<p>which is silly boilerplate</p>



<a name="169904584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169904584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169904584">(Jul 08 2019 at 21:01)</a>:</h4>
<p>Is it a common thing to have an async fn return a boxed future?</p>



<a name="169904592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169904592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169904592">(Jul 08 2019 at 21:01)</a>:</h4>
<p>I guess it's a "stream-like" pattern</p>



<a name="169904597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169904597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169904597">(Jul 08 2019 at 21:01)</a>:</h4>
<p>sort of analogous to a "one shot channel"</p>



<a name="169904666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169904666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169904666">(Jul 08 2019 at 21:02)</a>:</h4>
<p>I wonder if the most logical fix is to make the "maybe lives across await" analysis more precise.</p>



<a name="169904680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169904680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169904680">(Jul 08 2019 at 21:02)</a>:</h4>
<p>it's certainly not uncommon, yes</p>



<a name="169904689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/mutuallly%20recursive%20async%20fn%20%2362284/near/169904689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/mutuallly.20recursive.20async.20fn.20.2362284.html#169904689">(Jul 08 2019 at 21:03)</a>:</h4>
<blockquote>
<p>I wonder if the most logical fix is to make the "maybe lives across await" analysis more precise.</p>
</blockquote>
<p>Yes, I think that's where the problem is here.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>